<%@ page import="au.org.ala.phylojive.Tree" %>



<div class="fieldcontain ${hasErrors(bean: treeInstance, field: 'name', 'error')} required">
	<label for="name">
		<g:message code="tree.name.label" default="Name" />
		<span class="required-indicator">*</span>
	</label>
	<g:textField name="name" required="" value="${treeInstance?.name}"/>
</div>

<div class="fieldcontain ${hasErrors(bean: treeInstance, field: 'owner', 'error')} required">
	<label for="owner">
		<g:message code="tree.owner.label" default="Owner" />
		<span class="required-indicator">*</span>
	</label>
	<g:select id="owner" name="owner.id" from="${au.org.ala.phylojive.User.list()}" optionKey="id" required="" value="${treeInstance?.owner?.id}" class="many-to-one"/>
</div>

<div class="fieldcontain ${hasErrors(bean: treeInstance, field: 'isPublic', 'error')} ">
	<label for="isPublic">
		<g:message code="tree.isPublic.label" default="Is Public" />
		
	</label>
	<g:checkBox name="isPublic" value="${treeInstance?.isPublic}" />
</div>

<div class="fieldcontain ${hasErrors(bean: treeInstance, field: 'newick', 'error')} required">
	<label for="newick">
		<g:message code="tree.newick.label" default="Newick" />
		<span class="required-indicator">*</span>
	</label>
	<g:textArea name="newick" cols="40" rows="5" required="" value="${treeInstance?.newick}"/>
</div>

<div class="fieldcontain ${hasErrors(bean: treeInstance, field: 'characters', 'error')} ">
	<label for="characters">
		<g:message code="tree.characters.label" default="Characters" />
		
	</label>
	<g:textArea name="characters" cols="40" rows="5" maxlength="600000" value="${treeInstance?.characters}"/>
    <script type="text/javascript">
        // <!--
        function clickConvert(el) {
            console.log("converting to JSON 3");
            var csv = $(":input#characters").val();
            var separator = $(":input#separator").val();
            //console.log("csv", csv);
            if (csv) {
                var url = "${createLink(controller: 'tree', action: 'convertCsvToJson')}"; // ?csv=" + csv;
                var data = {
                    csv: csv,
                    separator: separator
                }
                //console.log("getJSON url = ", url);
                $.ajax({
                    url: url,
                    type: "POST",
                    data: data,
                    dataType: "text",
                    success: function(data) {
                        console.log("data = ", data);
                        if (data) {
                            $(":input#characters").val(data);
                        }
                    }
                });
//                $.get(url, data, function(data) {
//                    console.log("data = ", data);
//                    if (data) {
//                        $(":input#characters").val(data);
//                    }
//                });
            }
            return false;
        }

        $(document).ready(function() {
            $(".treeHelp abbr").qtip();
        });
        // -->
    </script>
    %{--<g:set var="charJsonFormat"><g:message code="tree.characters.charJson"/></g:set>--}%
    %{--<g:set var="charCsvFormat"><g:message code="tree.characters.charCsv"/></g:set>--}%
    <span class="treeHelp">Input characters in <abbr title="${g.message(code:"tree.characters.charJson")}"/>charJSON format</abbr>.
       Alternatively, you can paste <abbr title="${g.message(code:"tree.characters.charCsv")}"/>CSV data</abbr>
        and then click: <button id="convertCsvToJson" onclick="clickConvert(this); return false;">Convert to charJSON</button>
        <br/>internal separator: <input id="separator" size="5" value="" style="width:30px;"> (optional:
        for characters with multiple values)
    </span>
</div>

<div class="fieldcontain ${hasErrors(bean: treeInstance, field: 'attribution', 'error')} ">
	<label for="attribution">
		<g:message code="tree.attribution.label" default="Attribution" />
		
	</label>
	<g:textArea name="attribution" cols="40" rows="5" value="${treeInstance?.attribution}"/>
</div>

<div class="fieldcontain ${hasErrors(bean: treeInstance, field: 'highlight', 'error')} ">
	<label for="highlight">
		<g:message code="tree.highlight.label" default="Highlight" />
		
	</label>
	<g:select name="highlight" from="${1..10}" class="range" value="${fieldValue(bean: treeInstance, field: 'highlight')}" noSelection="['': '']"/>
</div>

<div class="fieldcontain ${hasErrors(bean: treeInstance, field: 'identifyLifeDataset', 'error')} ">
	<label for="identifyLifeDataset">
		<g:message code="tree.identifyLifeDataset.label" default="Identify Life Dataset" />
		
	</label>
	<g:textField name="identifyLifeDataset" value="${treeInstance?.identifyLifeDataset}"/>
</div>

